package com.yf.repo.modules.repo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.utils.BeanMapper;
import com.yf.repo.modules.repo.dto.RepoChapterDTO;
import com.yf.repo.modules.repo.entity.RepoChapter;
import com.yf.repo.modules.repo.service.RepoChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* <p>
* 题库章节控制器
* </p>
*
* @author 聪明笨狗
* @since 2020-12-01 10:44
*/
@Api(tags={"题库章节"})
@RestController
@RequestMapping("/api/repo/chapter")
public class RepoChapterController extends BaseController {

    @Autowired
    private RepoChapterService baseService;


    /**
     * 查找列表，每次最多返回200条数据
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "查找列表")
    @PostMapping("/list")
    public ApiRest<List<RepoChapterDTO>> list(@RequestBody RepoChapterDTO reqDTO) {

        //分页查询并转换
        QueryWrapper<RepoChapter> wrapper = new QueryWrapper<>();

        // 根据题库查询
        if(reqDTO!=null){
            if(!StringUtils.isBlank(reqDTO.getRepoId())){
                wrapper.lambda().eq(RepoChapter::getRepoId, reqDTO.getRepoId());
            }
        }

        //转换并返回
        List<RepoChapter> list = baseService.list(wrapper);

        //转换数据
        List<RepoChapterDTO> dtoList = BeanMapper.mapList(list, RepoChapterDTO.class);

        return super.success(dtoList);
    }
}
